﻿using B.S.Procurement.Domain;
using B.S.Procurement.Error;
using B.S.Procurement.Read.Api.Application.Command.ProductsModelCommand;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Procurement.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductsController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<ProductsController> logger;

        public ProductsController(IMediator mediator, ILogger<ProductsController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 查询产品信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiPaging<List<ProductsModel>>> QueryProducts([FromQuery] QueryProductsModelCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 反填产品信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<ProductsModel>>> ShowProducts([FromQuery] ShowProductsModelCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 不带条件查询所有
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<ProductsModel>>> GetProducts([FromQuery] GetProductsModelCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
